from selenium.webdriver.common.by import By

from common.Utils import FormDriver


class FormLogin:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://127.0.0.1:9580/sign-in.html"
        self.driver = FormDriver.driver
        self.driver.get(self.url)
    def FormLogWebTest(self):#测试页面元素
        #log是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page.page-center > div > div > div:nth-child(1) > div > div.text-center.mb-4 > img")
        #用户名提示是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page.page-center > div > div > div:nth-child(1) > div > div.card.card-md > div > h2")
        #用户名输入框是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#signInForm > div.mb-3 > label")
        #密码提示是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#username")
        #密码输入框是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#signInForm > div.mb-2 > label")
        #显示密码按钮是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#password_a > svg")
        #登录按钮是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#submit")
        #提示注册文本是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page.page-center > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3")
        #注册按钮是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page.page-center > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a")

        FormDriver.DribverScreeShot()


    def FormLoginSucTest(self):
            self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
            self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
            self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("2451725266")
            self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("52100czr")
            self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
            FormDriver.DribverScreeShot()

            #查找用户名
            #self.driver.find_element(By.CSS_SELECTOR,"#index_nav_nickname")
            #FormDriver.DribverScreeShot()



    def FormLoginDefete(self):
        # 错误的密码错误的账号
            self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("24517252")
            self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("52100c")
            self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
            self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div")
            self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
            self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
            FormDriver.DribverScreeShot()

        #错误的密码正确的账号
            self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("2451725266")
            self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("52100c")
            self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
            self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")
            self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
            self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
            FormDriver.DribverScreeShot()

    #正确的密码错误的账号
            self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("24517252")
            self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("52100czr")
            self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
            self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")
            self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
            self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
            FormDriver.DribverScreeShot()


    #空账号空密码
            self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
            self.driver.find_element(By.CSS_SELECTOR, "#signInForm > div.mb-3 > div")
            self.driver.find_element(By.CSS_SELECTOR, "#signInForm > div.mb-2 > div > div")
            self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
            self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
            FormDriver.DribverScreeShot()

    def FormLoginUsability(self):
        self.driver.find_element(By.CSS_SELECTOR,"#username").click()
        self.driver.find_element(By.CSS_SELECTOR,"#signInForm > div.mb-3 > div")
        self.driver.find_element(By.CSS_SELECTOR,"#password").click()
        self.driver.find_element(By.CSS_SELECTOR,"#signInForm > div.mb-2 > div > div")
        FormDriver.DribverScreeShot()















